home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / faceutils.py < prev    next >
Text File  |  2004-01-05  |  2KB  |  92 lines

  1. ######################################################
  2. #
  3. # Utilities for working with faces
  4. #
  5. #     tiglari@planetquake.com
  6. #
  7. ######################################################
  8.  
  9. #$Header: /cvsroot/quark/runtime/plugins/faceutils.py,v 1.3 2001/08/11 04:14:51 tiglari Exp $
  10.  
  11. from quarkpy.qutils import *
  12.  
  13. def cyclenext(i, len):
  14.   j = i+1
  15.   if j == len:
  16.     return 0
  17.   else:
  18.     return j
  19.  
  20. def cycleprev(i, len):
  21.   j = i-1
  22.   if j == 0:
  23.     return len
  24.   else:
  25.     return j
  26.  
  27. def vtx_index(vtxes, pos):
  28.   for i in range(len(vtxes)):
  29.     if not(vtxes[i]-pos):
  30.       return i
  31.  
  32. def abutting_vtx(l1, l2):
  33.   "gets the two vtx shared between l1 & l2, which are"
  34.   "supposed to be vertex-cyles of abutting faces"
  35.   "returns list of (el,ind) tuples, where el is from l1,"
  36.   "and ind is its index"
  37.   intx = []
  38.   pozzies = []
  39.   i = -1
  40.   for el1 in l1:
  41.     i = i+1
  42.     for el2 in l2 :
  43.       if not (el1-el2):
  44.         pozzies.append(i)
  45.         intx.append((el1,i))
  46.         break
  47.   if len(intx) != 2:
  48.     return []
  49.   if pozzies[0]==0 and pozzies[1]>1:
  50.     intx.reverse()
  51.   return intx
  52.     
  53. def intersection_vect(l1, l2):
  54.   "for points/vectors only"
  55.   "note that the points come out in the same order they have in l1"
  56.   shared = []
  57.   for el1 in l1:
  58.     for el2 in l2 :
  59.       if not (el1-el2):
  60.         shared.append(el1)
  61.         break
  62.   return shared
  63.  
  64. def shares_edge(face, poly, vtx1, vtx2):
  65.    vtxes = face.verticesof(poly)
  66.    list = intersection_vect([vtx1, vtx2], vtxes)
  67.    return len(list)==2
  68.  
  69.  
  70. def coplanar(f1, f2, opp=1):
  71.     "if opp==0, face normals must point in same direction"
  72.     o1 = f1.dist*f1.normal
  73.     o2 = f2.dist*f2.normal
  74. #    debug('coplanar')
  75.     if not f1.normal*(o2-o1):
  76.         if not f1.normal-f2.normal:
  77.             return 1
  78.         if opp and not f1.normal+f2.normal:
  79.             return 1
  80.     return 0
  81.     
  82.  
  83. #$Log: faceutils.py,v $
  84. #Revision 1.3  2001/08/11 04:14:51  tiglari
  85. #remove debug
  86. #
  87. #Revision 1.2  2001/04/15 06:05:52  tiglari
  88. #add coplanar function
  89. #
  90. #Revision 1.1  2001/04/01 04:43:48  tiglari
  91. #initial commit
  92. #